﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using GrewalCRM.Entities;

namespace GrewalCRM.DAL
{
  public abstract class BaseDALGrewalCRM
  {
    SqlConnection conn;
    SqlCommand cmd;
    SqlDataReader rdr;    
    string spName;

    #region Constructors
		/// <summary>
		/// Create a new instance using the default constructor
		/// </summary>
    public BaseDALGrewalCRM()
		{
      conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DEV"].ToString());
      cmd = new SqlCommand(spName, conn);
      cmd.CommandType = System.Data.CommandType.StoredProcedure;     
		}

    public BaseDALGrewalCRM(string SPName):this()
    {
      spName = SPName;      
    }

  #endregion

    #region Public Properties
    /// <summary>
    /// Indicates whether the entity is changed and requires saving or not.
    /// </summary>
    protected SqlCommand  Cmd
    {
      get { return cmd; }     
    }

    protected SqlDataReader Rdr
    {
      get { return rdr; }
      set { rdr = value; }
    }  
    #endregion

    #region Protected Methods
    public abstract int AddNew(BaseEntitiesGrewalCRM Entity);
    public abstract int Update(BaseEntitiesGrewalCRM Entity);
    public abstract int Delete(BaseEntitiesGrewalCRM Entity);
    public abstract List<BaseEntitiesGrewalCRM> GetAll();
    public abstract BaseEntitiesGrewalCRM GetByID(int ID);
    public abstract void FillEntity(BaseEntitiesGrewalCRM Entity);
    #endregion
  }
}
